
using System;
using System.Runtime.Serialization;
using System.Collections.Generic;

using PolePosition.v3.EntityLibrary;

namespace PolePosition.v3.EntityFactory
{
	/// <summary>
	/// Methods used to get and save data for a LookupTables Class
	/// </summary>
	public sealed partial class LookupTableFactory
	{	
		/// <summary>
        /// Retrieve a LookupTable Class with all ProjectCommon2.Generics.EntityCollection Populated
        /// </summary>
        /// <returns>
        /// LookupTable Class that contains a ProjectCommon2.Generics.EntityCollection<Entity>
        /// for each entity that is defined as a lookup table
        /// </returns>
		public static LookupTables GetLookups()
		{
			return GetLookups(GetAllLookupTablesList());
		}
		
		/// <summary>
        /// Retrieve a LookupTable Class with designated ProjectCommon2.Generics.EntityCollections Populated
        /// </summary>
        /// <param name="tables">
        /// A LookupTables.Tables Array. Each member of the enumeration represents a 
        /// ProjectCommon2.Generics.EntityCollection in the LookupTable Class. Define which
        /// of the Collections you wish to be populated by including them in the array. To 
        /// populate all possible ProjectCommon2.Generics.EntityCollections fill the array 
        /// with LookupTables.Tables.All
        /// </param>
        /// <returns>
        /// LookupTable Class that contains a ProjectCommon2.Generics.EntityCollection<Entity>
        /// for each LookupTables.Tables that is defined as in the table argument
        /// </returns>
		public static LookupTables GetLookups(LookupTables.Tables[] tables)
		{
 			//convert array to list And call list overload
            return GetLookups(new List<LookupTables.Tables>(tables));
		}
		
		/// <summary>
        /// Retrieve a LookupTable Class with designated ProjectCommon2.Generics.EntityCollections Populated
        /// </summary>
        /// <param name="tables">
        /// A LookupTables.Tables List. Each member of the enumeration represents a 
        /// ProjectCommon2.Generics.EntityCollection in the LookupTable Class. Define which
        /// of the Collections you wish to be populated by including them in the list. To 
        /// populate all possible ProjectCommon2.Generics.EntityCollections fill the array 
        /// with LookupTables.Tables.All
        /// </param>
        /// <returns>
        /// LookupTable Class that contains a ProjectCommon2.Generics.EntityCollection<Entity>
        /// for each LookupTables.Tables that is defined as in the table argument
        /// </returns>
		public static LookupTables GetLookups(List<LookupTables.Tables> tables)
		{
		    //do we get all - if so - change tables to contain all enums
            if (tables == null || tables.Contains(LookupTables.Tables.All))
                tables = GetAllLookupTablesList();

			LookupTables _lookups = new LookupTables();

            // build SqlCommand
            System.Data.SqlClient.SqlCommand SqlCmd;
            SqlCmd = new System.Data.SqlClient.SqlCommand();
            SqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
            SqlCmd.CommandText = "up_LookupTables_Select";

			System.Data.SqlClient.SqlParameter SqlParam;
			//add SQL Parameters for each lookup table that will be retrieved
			foreach (LookupTables.Tables _table in tables)
            {
                switch (_table)
                {
					case LookupTables.Tables.CentralOffices:
						//Add @CentralOffice Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@CentralOffice";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.DistributionClasses:
						//Add @DistributionClasses Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@DistributionClasses";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.DistributionLengths:
						//Add @DistributionLength Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@DistributionLength";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.DistributionMeterNotes:
						//Add @DistributionMeterNote Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@DistributionMeterNote";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.DistributionPhases:
						//Add @DistributionPhase Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@DistributionPhase";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.DistributionsTopTypes:
						//Add @DistributionsTopType Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@DistributionsTopType";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.Handheld:
						//Add @Handheld Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@Handheld";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.MetersTopTypes:
						//Add @MetersTopType Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@MetersTopType";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.RemedyStatus:
						//Add @RemedyStatus Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@RemedyStatus";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.VendorContactTypes:
						//Add @VendorContactType Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@VendorContactType";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.VendorInspVisitXmissionStructuresInspectionType:
						//Add @VendorInspVisitXmissionStructuresInspectionType Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@VendorInspVisitXmissionStructuresInspectionType";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.VendorInspVisitXmissionStructuresNotes:
						//Add @VendorInspVisitXmissionStructuresNote Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@VendorInspVisitXmissionStructuresNote";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.VendorInspVisitXmissionStructuresResultTypes:
						//Add @VendorInspVisitXmissionStructuresResultType Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@VendorInspVisitXmissionStructuresResultType";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.VendorVisitType:
						//Add @VendorVisitType Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@VendorVisitType";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.XMissionStructuresPoleClasses:
						//Add @XMissionStructuresPoleClasses Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@XMissionStructuresPoleClasses";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.XMissionStructuresPoleSpecies:
						//Add @XMissionStructuresPoleSpecies Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@XMissionStructuresPoleSpecies";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.XMissionStructuresPoleTopTypes:
						//Add @XMissionStructuresPoleTopType Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@XMissionStructuresPoleTopType";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.XMissionStructuresPoleTreatments:
						//Add @XMissionStructuresPoleTreatment Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@XMissionStructuresPoleTreatment";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.XMissionStructuresTopTypes:
						//Add @XMissionStructuresTopType Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@XMissionStructuresTopType";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.ReportsProject:
						//Add @ReportsProject Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@ReportsProject";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.Settings:
						//Add @Setting Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@Setting";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
					case LookupTables.Tables.UtilityContactTypes:
						//Add @UtilityContactType Parameter
						SqlParam = new System.Data.SqlClient.SqlParameter();
						SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
						SqlParam.ParameterName = "@UtilityContactType";
						SqlParam.Direction = System.Data.ParameterDirection.Input;
						SqlParam.Value = true;
						SqlCmd.Parameters.Add(SqlParam);
						break;
                    case LookupTables.Tables.VendorDistributionLookups:
                        //Add @VendorDistributionLookups Parameter
                        SqlParam = new System.Data.SqlClient.SqlParameter();
                        SqlParam.SqlDbType = System.Data.SqlDbType.Bit;
                        SqlParam.ParameterName = "@VendorDistributionLookups";
                        SqlParam.Direction = System.Data.ParameterDirection.Input;
                        SqlParam.Value = true;
                        SqlCmd.Parameters.Add(SqlParam);
                        break;
                    case LookupTables.Tables.All:
                    default:
                        //do nothing - "All" handled above
                        break;
                }
            }
			
			System.Data.DataSet _LookupData = null;
			_LookupData = ProjectCommon2.Helpers.SqlHelper.ExecuteDataSet(SqlCmd);
			
			int _tableIndex = 0;
			
			if (tables.Contains(LookupTables.Tables.CentralOffices))
			{
				_lookups.CentralOffices = new ProjectCommon2.Generics.EntityCollection<CentralOfficeEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.DistributionClasses))
			{
				_lookups.DistributionClasses = new ProjectCommon2.Generics.EntityCollection<DistributionClassesEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.DistributionLengths))
			{
				_lookups.DistributionLengths = new ProjectCommon2.Generics.EntityCollection<DistributionLengthEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.DistributionMeterNotes))
			{
				_lookups.DistributionMeterNotes = new ProjectCommon2.Generics.EntityCollection<DistributionMeterNoteEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.DistributionPhases))
			{
				_lookups.DistributionPhases = new ProjectCommon2.Generics.EntityCollection<DistributionPhaseEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.DistributionsTopTypes))
			{
				_lookups.DistributionsTopTypes = new ProjectCommon2.Generics.EntityCollection<DistributionsTopTypeEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.Handheld))
			{
				_lookups.Handheld = new ProjectCommon2.Generics.EntityCollection<HandheldEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.MetersTopTypes))
			{
				_lookups.MetersTopTypes = new ProjectCommon2.Generics.EntityCollection<MetersTopTypeEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.RemedyStatus))
			{
				_lookups.RemedyStatus = new ProjectCommon2.Generics.EntityCollection<RemedyStatusEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.VendorContactTypes))
			{
				_lookups.VendorContactTypes = new ProjectCommon2.Generics.EntityCollection<VendorContactTypeEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.VendorInspVisitXmissionStructuresInspectionType))
			{
				_lookups.VendorInspVisitXmissionStructuresInspectionType = new ProjectCommon2.Generics.EntityCollection<VendorInspVisitXmissionStructuresInspectionTypeEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.VendorInspVisitXmissionStructuresNotes))
			{
				_lookups.VendorInspVisitXmissionStructuresNotes = new ProjectCommon2.Generics.EntityCollection<VendorInspVisitXmissionStructuresNoteEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.VendorInspVisitXmissionStructuresResultTypes))
			{
				_lookups.VendorInspVisitXmissionStructuresResultTypes = new ProjectCommon2.Generics.EntityCollection<VendorInspVisitXmissionStructuresResultTypeEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.VendorVisitType))
			{
				_lookups.VendorVisitType = new ProjectCommon2.Generics.EntityCollection<VendorVisitTypeEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.XMissionStructuresPoleClasses))
			{
				_lookups.XMissionStructuresPoleClasses = new ProjectCommon2.Generics.EntityCollection<XMissionStructuresPoleClassesEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.XMissionStructuresPoleSpecies))
			{
				_lookups.XMissionStructuresPoleSpecies = new ProjectCommon2.Generics.EntityCollection<XMissionStructuresPoleSpeciesEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.XMissionStructuresPoleTopTypes))
			{
				_lookups.XMissionStructuresPoleTopTypes = new ProjectCommon2.Generics.EntityCollection<XMissionStructuresPoleTopTypeEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.XMissionStructuresPoleTreatments))
			{
				_lookups.XMissionStructuresPoleTreatments = new ProjectCommon2.Generics.EntityCollection<XMissionStructuresPoleTreatmentEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.XMissionStructuresTopTypes))
			{
				_lookups.XMissionStructuresTopTypes = new ProjectCommon2.Generics.EntityCollection<XMissionStructuresTopTypeEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.ReportsProject))
			{
				_lookups.ReportsProject = new ProjectCommon2.Generics.EntityCollection<ReportsProjectEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.Settings))
			{
				_lookups.Settings = new ProjectCommon2.Generics.EntityCollection<SettingEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}
			
			if (tables.Contains(LookupTables.Tables.UtilityContactTypes))
			{
				_lookups.UtilityContactTypes = new ProjectCommon2.Generics.EntityCollection<UtilityContactTypeEntity>(_LookupData.Tables[_tableIndex]);
				_tableIndex ++;
			}

            if (tables.Contains(LookupTables.Tables.VendorDistributionLookups))
            {
                _lookups.VendorDistributionLookups = new ProjectCommon2.Generics.EntityCollection<VendorDistributionLookupsEntity>(_LookupData.Tables[_tableIndex]);
                _tableIndex++;
            }
			
            return _lookups;
		}
		
		/// <summary>
        /// Save All ProjectCommon2.Generics.EntityCollections of the LookupTables Class
        /// </summary>
        /// <param name="lookups">
        /// A LookupTables Class containing ProjectCommon2.Generics.EntityCollections that should be saved
        /// </param>
        /// <returns>
        /// An updated LookupTable Class from the data that was saved
        /// </returns>
        /// <remarks>Only EntityCollections that are dirty will be saved even if designated</remarks>
        public static LookupTables SaveLookups(LookupTables lookups)
        {
            return SaveLookups(GetAllLookupTablesList(), lookups);
        }
		
		/// <summary>
        /// Save designated ProjectCommon2.Generics.EntityCollections of the LookupTables Class
        /// </summary>
        /// <param name="tables">
        /// A LookupTables.Tables Array. Each member of the enumeration represents a 
        /// ProjectCommon2.Generics.EntityCollection in the LookupTable Class. Define which
        /// of the Collections you wish to save by including them in the array. To 
        /// save all possible ProjectCommon2.Generics.EntityCollections fill the array 
        /// with LookupTables.Tables.All
        /// </param>
        /// <param name="lookups">
        /// A LookupTables Class containing ProjectCommon2.Generics.EntityCollections that should be saved
        /// </param>
        /// <returns>
        /// An updated LookupTable Class from the data that was saved
        /// </returns>
        /// <remarks>Only EntityCollections that are dirty will be saved even if designated</remarks>
		public static LookupTables SaveLookup(LookupTables.Tables[] tables, LookupTables lookups)
		{
            //convert array to list and call list overload
            return SaveLookups(new List<LookupTables.Tables>(tables), lookups);
		}
		
		/// <summary>
        /// Save designated ProjectCommon2.Generics.EntityCollections of the LookupTables Class
        /// </summary>
        /// <param name="tables">
        /// A LookupTables.Tables List. Each member of the enumeration represents a 
        /// ProjectCommon2.Generics.EntityCollection in the LookupTable Class. Define which
        /// of the Collections you wish to save by including them in the list. To 
        /// save all possible ProjectCommon2.Generics.EntityCollections fill the list 
        /// with LookupTables.Tables.All
        /// </param>
        /// <param name="lookups">
        /// A LookupTables Class containing ProjectCommon2.Generics.EntityCollections that should be saved
        /// </param>
        /// <returns>
        /// An updated LookupTable Class from the data that was saved
        /// </returns>
        /// <remarks>Only EntityCollections that are dirty will be saved even if designated</remarks>
		public static LookupTables SaveLookups(List<LookupTables.Tables> tables, LookupTables lookups)
		{
			//do we save all - if so - change tables to contain all enums
            if (tables == null || tables.Contains(LookupTables.Tables.All))
                tables = GetAllLookupTablesList();

            foreach (LookupTables.Tables _table in tables)
            {
                switch (_table)
                {
					case LookupTables.Tables.CentralOffices:
						if (lookups.CentralOffices != null)
							CentralOfficeFactory.Save(lookups.CentralOffices);
						break;
					case LookupTables.Tables.DistributionClasses:
						if (lookups.DistributionClasses != null)
							DistributionClassesFactory.Save(lookups.DistributionClasses);
						break;
					case LookupTables.Tables.DistributionLengths:
						if (lookups.DistributionLengths != null)
							DistributionLengthFactory.Save(lookups.DistributionLengths);
						break;
					case LookupTables.Tables.DistributionMeterNotes:
						if (lookups.DistributionMeterNotes != null)
							DistributionMeterNoteFactory.Save(lookups.DistributionMeterNotes);
						break;
					case LookupTables.Tables.DistributionPhases:
						if (lookups.DistributionPhases != null)
							DistributionPhaseFactory.Save(lookups.DistributionPhases);
						break;
					case LookupTables.Tables.DistributionsTopTypes:
						if (lookups.DistributionsTopTypes != null)
							DistributionsTopTypeFactory.Save(lookups.DistributionsTopTypes);
						break;
					case LookupTables.Tables.Handheld:
						if (lookups.Handheld != null)
							HandheldFactory.Save(lookups.Handheld);
						break;
					case LookupTables.Tables.MetersTopTypes:
						if (lookups.MetersTopTypes != null)
							MetersTopTypeFactory.Save(lookups.MetersTopTypes);
						break;
					case LookupTables.Tables.RemedyStatus:
						if (lookups.RemedyStatus != null)
							RemedyStatusFactory.Save(lookups.RemedyStatus);
						break;
					case LookupTables.Tables.VendorContactTypes:
						if (lookups.VendorContactTypes != null)
							VendorContactTypeFactory.Save(lookups.VendorContactTypes);
						break;
					case LookupTables.Tables.VendorInspVisitXmissionStructuresInspectionType:
						if (lookups.VendorInspVisitXmissionStructuresInspectionType != null)
							VendorInspVisitXmissionStructuresInspectionTypeFactory.Save(lookups.VendorInspVisitXmissionStructuresInspectionType);
						break;
					case LookupTables.Tables.VendorInspVisitXmissionStructuresNotes:
						if (lookups.VendorInspVisitXmissionStructuresNotes != null)
							VendorInspVisitXmissionStructuresNoteFactory.Save(lookups.VendorInspVisitXmissionStructuresNotes);
						break;
					case LookupTables.Tables.VendorInspVisitXmissionStructuresResultTypes:
						if (lookups.VendorInspVisitXmissionStructuresResultTypes != null)
							VendorInspVisitXmissionStructuresResultTypeFactory.Save(lookups.VendorInspVisitXmissionStructuresResultTypes);
						break;
					case LookupTables.Tables.VendorVisitType:
						if (lookups.VendorVisitType != null)
							VendorVisitTypeFactory.Save(lookups.VendorVisitType);
						break;
					case LookupTables.Tables.XMissionStructuresPoleClasses:
						if (lookups.XMissionStructuresPoleClasses != null)
							XMissionStructuresPoleClassesFactory.Save(lookups.XMissionStructuresPoleClasses);
						break;
					case LookupTables.Tables.XMissionStructuresPoleSpecies:
						if (lookups.XMissionStructuresPoleSpecies != null)
							XMissionStructuresPoleSpeciesFactory.Save(lookups.XMissionStructuresPoleSpecies);
						break;
					case LookupTables.Tables.XMissionStructuresPoleTopTypes:
						if (lookups.XMissionStructuresPoleTopTypes != null)
							XMissionStructuresPoleTopTypeFactory.Save(lookups.XMissionStructuresPoleTopTypes);
						break;
					case LookupTables.Tables.XMissionStructuresPoleTreatments:
						if (lookups.XMissionStructuresPoleTreatments != null)
							XMissionStructuresPoleTreatmentFactory.Save(lookups.XMissionStructuresPoleTreatments);
						break;
					case LookupTables.Tables.XMissionStructuresTopTypes:
						if (lookups.XMissionStructuresTopTypes != null)
							XMissionStructuresTopTypeFactory.Save(lookups.XMissionStructuresTopTypes);
						break;
					case LookupTables.Tables.ReportsProject:
						if (lookups.ReportsProject != null)
							ReportsProjectFactory.Save(lookups.ReportsProject);
						break;
					case LookupTables.Tables.Settings:
						if (lookups.Settings != null)
							SettingFactory.Save(lookups.Settings);
						break;
					case LookupTables.Tables.UtilityContactTypes:
						if (lookups.UtilityContactTypes != null)
							UtilityContactTypeFactory.Save(lookups.UtilityContactTypes);
						break;
                    case LookupTables.Tables.VendorDistributionLookups:
                        if (lookups.VendorDistributionLookups != null)
                            VendorDistributionLookupsFactory.Save(lookups.VendorDistributionLookups);
                        break;
                    case LookupTables.Tables.All:
                    default:
                        //do nothing - "All" handled above
                        break;
                }
            }
            return lookups;
		}
		
		/// <summary>
        /// Creates a List with All possible LookupTables.Tables
        /// </summary>
        /// <returns>A Generic List of LookupTables.Tables</returns>
		private static List<LookupTables.Tables> GetAllLookupTablesList()
        {
            List<LookupTables.Tables> _tables = new List<LookupTables.Tables>();
			_tables.Add(LookupTables.Tables.CentralOffices);
			_tables.Add(LookupTables.Tables.DistributionClasses);
			_tables.Add(LookupTables.Tables.DistributionLengths);
			_tables.Add(LookupTables.Tables.DistributionMeterNotes);
			_tables.Add(LookupTables.Tables.DistributionPhases);
			_tables.Add(LookupTables.Tables.DistributionsTopTypes);
			_tables.Add(LookupTables.Tables.Handheld);
			_tables.Add(LookupTables.Tables.MetersTopTypes);
			_tables.Add(LookupTables.Tables.RemedyStatus);
			_tables.Add(LookupTables.Tables.VendorContactTypes);
			_tables.Add(LookupTables.Tables.VendorInspVisitXmissionStructuresInspectionType);
			_tables.Add(LookupTables.Tables.VendorInspVisitXmissionStructuresNotes);
			_tables.Add(LookupTables.Tables.VendorInspVisitXmissionStructuresResultTypes);
			_tables.Add(LookupTables.Tables.VendorVisitType);
			_tables.Add(LookupTables.Tables.XMissionStructuresPoleClasses);
			_tables.Add(LookupTables.Tables.XMissionStructuresPoleSpecies);
			_tables.Add(LookupTables.Tables.XMissionStructuresPoleTopTypes);
			_tables.Add(LookupTables.Tables.XMissionStructuresPoleTreatments);
			_tables.Add(LookupTables.Tables.XMissionStructuresTopTypes);
			_tables.Add(LookupTables.Tables.ReportsProject);
			_tables.Add(LookupTables.Tables.Settings);
			_tables.Add(LookupTables.Tables.UtilityContactTypes);
            _tables.Add(LookupTables.Tables.VendorDistributionLookups);
			return _tables;
        }
	}
}